package com.pinyoumei.app.activity.ShoppingCenter;

import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.pinyoumei.app.R;
import com.pinyoumei.app.activity.BaseActivity;
import com.pinyoumei.app.activity.ProductDetailActivity;
import com.pinyoumei.app.activity.ProductDetailPtActivity;
import com.pinyoumei.app.adapter.HpSearchListAdapter;
import com.pinyoumei.app.adapter.JDListAdapter;
import com.pinyoumei.app.adapter.PddListAdapter;
import com.pinyoumei.app.adapter.TaoBaoListAdapter;
import com.pinyoumei.app.adapter.WphListAdapter;
import com.pinyoumei.app.bean.GoodDetailsBean;
import com.pinyoumei.app.bean.HpSearchBean;
import com.pinyoumei.app.bean.ShopCenterMainBean;
import com.pinyoumei.app.bean.TabEntity;
import com.pinyoumei.app.bean.TaobaoListBean;
import com.pinyoumei.app.bean.WphBean;
import com.pinyoumei.app.network.Constants;
import com.pinyoumei.app.utils.SPUtils;
import com.pinyoumei.app.utils.SignatureUtils;
import com.pinyoumei.app.utils.ToastUtils;
import com.pinyoumei.app.view.CommonTabLayout;
import com.pinyoumei.app.view.CustomTabEntity;
import com.pinyoumei.app.view.OnTabSelectListener;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2020-12-23.
 * --------- 日期 ------- 维护人 ------------ 变更内容 --------
 * 2020-12-23        Administrator             新增Person类
 * 2020-12-23        Administrator             增加sex属性
 * 搜索列表
 */
public class ShopSearchListActivity extends BaseActivity implements View.OnClickListener {

    private int titles_position;
    private String query_name;
    private EditText etSearch;
    private CommonTabLayout tl5;
    private LinearLayout ll1;
    private ImageView iv1;
    private LinearLayout ll2;
    private ImageView iv2;
    private ImageView iv22;
    private LinearLayout ll3;
    private ImageView iv3;
    private ImageView iv33;
    private CheckBox checkbox;
    private RecyclerView rvItem;
    private String[] titles;
    private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();
    private boolean Is_sale = true;
    private boolean Is_price = true;
    private boolean Is_check = true;
    private int sortType = 0;
    private int has_coupon = 0;
    private int page = 1;
    private SmartRefreshLayout swipeRefreshLayout;
    private List<TaobaoListBean.ResultBean.GoodsListBean> goods_list = new ArrayList<>();
    private List<WphBean.ResultBean.GoodsListBean> wph_goods_list = new ArrayList<>();
    private String title = "";
    private TaoBaoListAdapter taoBaoListAdapter;
    private PddListAdapter pddListAdapter;
    private JDListAdapter jdListAdapter;
    private WphListAdapter wphListAdapter;
//    private LinearLayout ll_check;
    private HpSearchListAdapter hpSearchListAdapter;
    private TextView tv_1;
    private TextView tv_2;
    private TextView tv_3;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shop_search_list);

        titles_position = getIntent().getIntExtra("titles_position", 0);
        query_name = getIntent().getStringExtra("query_name");

        InitWidget();
        SelectTypeData();

    }

    private void InitWidget() {

        RelativeLayout relativeFinish = findViewById(R.id.relative_finish);
        relativeFinish.setOnClickListener(this);
        etSearch = findViewById(R.id.et_search);
        etSearch.setText(query_name);
        etSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                    SelectTypeData();
                    return true;
                }

                return false;
            }
        });

        tl5 = findViewById(R.id.tl_5);

        tv_1 = findViewById(R.id.tv_1);
        tv_2 = findViewById(R.id.tv_2);
        tv_3 = findViewById(R.id.tv_3);

        LinearLayout ll1 = findViewById(R.id.ll_1);
        ll1.setOnClickListener(this);
        iv1 = findViewById(R.id.iv_1);
        LinearLayout ll2 = findViewById(R.id.ll_2);
        ll2.setOnClickListener(this);
        iv2 = findViewById(R.id.iv_2);
        iv22 = findViewById(R.id.iv_22);
        LinearLayout ll3 = findViewById(R.id.ll_3);
        ll3.setOnClickListener(this);
//        ll_check = findViewById(R.id.ll_check);
//        ll_check.setOnClickListener(this);
        iv3 = findViewById(R.id.iv_3);
        iv33 = findViewById(R.id.iv_33);
        checkbox = findViewById(R.id.checkbox);
        rvItem = findViewById(R.id.rv_item);


        switch (Constants.BIND_PDD) {
            case 0:
                titles = new String[]{"拼优美", "淘宝", "京东", "唯品会"};

                break;

            case 1:
                titles = new String[]{"拼优美", "淘宝", "拼多多", "京东", "唯品会"};
                break;

            default:
                break;
        }

        for (int i = 0; i < titles.length; i++) {
            mTabEntities.add(new TabEntity(titles[i]));
        }


        tl5.setTabData(mTabEntities);
        tl5.getTitleView(titles_position).setTextSize(17f);
        tl5.getTitleView(titles_position).setTypeface(Typeface.DEFAULT_BOLD);
        title = (String) tl5.getTitleView(titles_position).getText();
        tl5.setOnTabSelectListener(new OnTabSelectListener() {


            @Override
            public void onTabSelect(int position) {
                for (int i = 0; i < tl5.getTabCount(); i++) {
                    if (position == i) {
                        //选中的文字
                        tl5.getTitleView(position).setTextSize(17f);
                        tl5.getTitleView(0).setTypeface(Typeface.DEFAULT_BOLD);
                        title = (String) tl5.getTitleView(position).getText();


                    } else {
                        //未选中的文字，并且设置未选中时的不加粗
                        tl5.getTitleView(i).setTextSize(12f);
                        tl5.getTitleView(0).setTypeface(Typeface.DEFAULT);

                    }

//                    if (position == 3 || position == 0) {
//                        ll_check.setVisibility(View.GONE);
//                    } else {
//                        ll_check.setVisibility(View.VISIBLE);
//                    }

                }

                SelectTypeData();
            }

            @Override
            public void onTabReselect(int position) {

            }
        });

        swipeRefreshLayout = findViewById(R.id.swipeRefreshLayout);
        swipeRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                page++;
                switch (title) {
                    case "拼优美":
                        HPLoadMoreData(query_name);
                        break;

                    case "淘宝":
                        LoadMoreTaoBaoData(query_name);

                        break;

                    case "京东":
                        JDLoadMoreData(query_name);

                        break;
                    case "拼多多":
                        PddLoadMoreData(query_name);

                        break;
                    case "唯品会":

                        WphLoadMoreData(query_name);

                        break;
                    default:
                        break;
                }
                swipeRefreshLayout.finishLoadMore();
            }
        });
    }


    @Override
    public void onClick(View v) {
        iv1.setImageResource(R.mipmap.ic_black_down);
        iv2.setImageResource(R.mipmap.ic_black_up);
        iv22.setImageResource(R.mipmap.ic_black_down);
        iv3.setImageResource(R.mipmap.ic_black_up);
        iv33.setImageResource(R.mipmap.ic_black_down);

        page = 1;


        switch (v.getId()) {
            case R.id.relative_finish:
                finish();
                break;
            case R.id.ll_1:
                tv_1.setTextColor(ContextCompat.getColor(ShopSearchListActivity.this,R.color.green_bg2));
                tv_2.setTextColor(ContextCompat.getColor(ShopSearchListActivity.this,R.color.text_gray2));
                tv_3.setTextColor(ContextCompat.getColor(ShopSearchListActivity.this,R.color.text_gray2));
                iv1.setImageResource(R.mipmap.ic_red_down);
                sortType = 0;
                SelectTypeData();
                break;
            case R.id.ll_2:

                tv_2.setTextColor(ContextCompat.getColor(ShopSearchListActivity.this,R.color.green_bg2));
                tv_1.setTextColor(ContextCompat.getColor(ShopSearchListActivity.this,R.color.text_gray2));
                tv_3.setTextColor(ContextCompat.getColor(ShopSearchListActivity.this,R.color.text_gray2));

                if (Is_sale) {
                    iv22.setImageResource(R.mipmap.ic_red_down);
                    Is_sale = false;
                    sortType = 2;
                    SelectTypeData();
                } else {
                    iv2.setImageResource(R.mipmap.ic_red_up);
                    Is_sale = true;
                    sortType = 1;
                    SelectTypeData();
                }

                break;
            case R.id.ll_3:
                tv_3.setTextColor(ContextCompat.getColor(ShopSearchListActivity.this,R.color.green_bg2));
                tv_1.setTextColor(ContextCompat.getColor(ShopSearchListActivity.this,R.color.text_gray2));
                tv_2.setTextColor(ContextCompat.getColor(ShopSearchListActivity.this,R.color.text_gray2));


                if (Is_price) {
                    iv33.setImageResource(R.mipmap.ic_red_down);
                    Is_price = false;

                    sortType = 4;
                    SelectTypeData();
                } else {
                    iv3.setImageResource(R.mipmap.ic_red_up);
                    Is_price = true;

                    sortType = 3;
                    SelectTypeData();
                }

                break;
//            case R.id.ll_check:
//                if (Is_check) {
//                    checkbox.setChecked(true);
//                    Is_check = false;
//                    has_coupon = 1;
//                    SelectTypeData();
//                } else {
//                    checkbox.setChecked(false);
//                    Is_check = true;
//
//                    has_coupon = 0;
//                    SelectTypeData();
//                }
//
//
//                break;
            default:
                break;
        }
    }

    private void SelectTypeData() {
        switch (title) {
            case "拼优美":
                HPData(query_name);
                break;
            case "淘宝":
                TaoBaoData(query_name);
                break;

            case "京东":
                JDData(query_name);
                break;
            case "拼多多":
                PddData(query_name);
                break;
            case "唯品会":
                WphData(query_name);
//                ll_check.setVisibility(View.GONE);
                break;
            default:
                break;
        }
    }


    private void TaoBaoData(String goods_title) {

        Map<String, Object> map = new HashMap<>();
        map.put("user_id", SPUtils.getAppUserId(ShopSearchListActivity.this));
        map.put("goods_title", goods_title);
        map.put("sortType", sortType);
        map.put("has_coupon", has_coupon);
        map.put("page", 1);
        map.put("limit", 10);


        OkGo.<String>post(Constants.SHOPPING_LIST)
                .params("user_id", SPUtils.getAppUserId(ShopSearchListActivity.this))
                .params("goods_title", goods_title)
                .params("sortType", sortType)
                .params("has_coupon", has_coupon)

                .params("page", 1)
                .params("limit", 10)
                .params("sign", SignatureUtils.createSignature(map, Constants.SIGN_SECRET))
                .execute(new StringCallback() {


                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        loadingDailog.show();
                    }


                    @Override
                    public void onSuccess(Response<String> response) {
                        setData(response);

                    }

                    private void setData(Response<String> response) {
                        loadingDailog.dismiss();
                        TaobaoListBean toBaoBean = gson.fromJson(response.body(), TaobaoListBean.class);
                        if (toBaoBean.getCode() >= 0) {
                            //列表
                            goods_list.clear();
                            goods_list.addAll(toBaoBean.getResult().getGoods_list());
                            taoBaoListAdapter = new TaoBaoListAdapter(R.layout.item_shop_3, null);
                            rvItem.setLayoutManager(new LinearLayoutManager(ShopSearchListActivity.this, LinearLayoutManager.VERTICAL, false));
                            rvItem.setAdapter(taoBaoListAdapter);
                            taoBaoListAdapter.setNewData(goods_list);
                            View notDataView = getLayoutInflater().inflate(R.layout.item_empty_view, (ViewGroup) rvItem.getParent(), false);
                            taoBaoListAdapter.setEmptyView(notDataView);


                            taoBaoListAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {


                                @Override
                                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                                    Intent intent = new Intent(ShopSearchListActivity.this, ShopItemDetailActivity.class);
                                    Bundle bundle = new Bundle();
                                    ShopCenterMainBean.ResultBean.ShowGoodsListBean.GoodsListBean goodsListBean = goods_list.get(position);
                                    bundle.putString("type", "tb");
                                    bundle.putSerializable("goodsListBean", goodsListBean);
                                    intent.putExtras(bundle);
                                    startActivity(intent);
                                }
                            });


                        } else {
                            ToastUtils.showShort(toBaoBean.getMsg());
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        loadingDailog.dismiss();
                    }
                });


    }


    private void LoadMoreTaoBaoData(String goods_title) {

        Map<String, Object> map = new HashMap<>();
        map.put("user_id", SPUtils.getAppUserId(ShopSearchListActivity.this));
        map.put("goods_title", goods_title);
        map.put("sortType", sortType);
        map.put("has_coupon", has_coupon);
        map.put("page", page);
        map.put("limit", 10);


        OkGo.<String>post(Constants.SHOPPING_LIST)
                .params("user_id", SPUtils.getAppUserId(ShopSearchListActivity.this))
                .params("goods_title", goods_title)
                .params("sortType", sortType)
                .params("has_coupon", has_coupon)
                .params("page", page)
                .params("limit", 10)
                .params("sign", SignatureUtils.createSignature(map, Constants.SIGN_SECRET))
                .execute(new StringCallback() {


                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        loadingDailog.show();
                    }


                    @Override
                    public void onSuccess(Response<String> response) {
                        setData(response);

                    }

                    private void setData(Response<String> response) {
                        loadingDailog.dismiss();
                        TaobaoListBean toBaoBean = gson.fromJson(response.body(), TaobaoListBean.class);
                        if (toBaoBean.getCode() >= 0) {
                            //列表

                            if (toBaoBean.getResult().getGoods_list() != null && toBaoBean.getResult().getGoods_list().size() > 0) {
                                //列表
//                                goods_list.addAll(toBaoBean.getResult().getGoods_list());
                                taoBaoListAdapter.addData(toBaoBean.getResult().getGoods_list());
                            }

                        } else {
                            ToastUtils.showShort(toBaoBean.getMsg());
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        loadingDailog.dismiss();
                    }
                });

    }


    //拼多多
    private void PddData(String goods_title) {

        Map<String, Object> map = new HashMap<>();
        map.put("user_id", SPUtils.getAppUserId(ShopSearchListActivity.this));
        map.put("query_type", 2);
        map.put("goods_title", goods_title);
        map.put("sortType", sortType);
        map.put("has_coupon", has_coupon);
        map.put("page", page);
        map.put("limit", 10);


        OkGo.<String>post(Constants.PDD_INDEX)
                .params("user_id", SPUtils.getAppUserId(ShopSearchListActivity.this))
                .params("query_type", 2)
                .params("goods_title", goods_title)
                .params("sortType", sortType)
                .params("has_coupon", has_coupon)
                .params("page", page)
                .params("limit", 10)
                .params("sign", SignatureUtils.createSignature(map, Constants.SIGN_SECRET))
                .execute(new StringCallback() {


                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        loadingDailog.show();
                    }


                    @Override
                    public void onSuccess(Response<String> response) {
                        setData(response);

                    }

                    private void setData(Response<String> response) {
                        loadingDailog.dismiss();
                        TaobaoListBean toBaoBean = gson.fromJson(response.body(), TaobaoListBean.class);
                        if (toBaoBean.getCode() >= 0) {
                            //列表

                            goods_list.clear();
                            //列表
                            goods_list.addAll(toBaoBean.getResult().getGoods_list());
                            pddListAdapter = new PddListAdapter(R.layout.item_shop_pdd, null);
                            rvItem.setLayoutManager(new LinearLayoutManager(ShopSearchListActivity.this, LinearLayoutManager.VERTICAL, false));

                            rvItem.setAdapter(pddListAdapter);

                            pddListAdapter.setNewData(goods_list);
                            View notDataView = getLayoutInflater().inflate(R.layout.item_empty_view, (ViewGroup) rvItem.getParent(), false);
                            pddListAdapter.setEmptyView(notDataView);

                        } else {
                            ToastUtils.showShort(toBaoBean.getMsg());
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        loadingDailog.dismiss();
                    }
                });


    }


    //拼多多
    private void PddLoadMoreData(String goods_title) {

        Map<String, Object> map = new HashMap<>();
        map.put("user_id", SPUtils.getAppUserId(ShopSearchListActivity.this));
        map.put("query_type", 2);
        map.put("goods_title", goods_title);
        map.put("sortType", sortType);
        map.put("has_coupon", has_coupon);
        map.put("page", page);
        map.put("limit", 10);


        OkGo.<String>post(Constants.PDD_INDEX)
                .params("user_id", SPUtils.getAppUserId(ShopSearchListActivity.this))
                .params("query_type", 2)
                .params("goods_title", goods_title)
                .params("sortType", sortType)
                .params("has_coupon", has_coupon)
                .params("page", page)
                .params("limit", 10)
                .params("sign", SignatureUtils.createSignature(map, Constants.SIGN_SECRET))
                .execute(new StringCallback() {


                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        loadingDailog.show();
                    }


                    @Override
                    public void onSuccess(Response<String> response) {
                        setData(response);

                    }

                    private void setData(Response<String> response) {
                        loadingDailog.dismiss();
                        TaobaoListBean toBaoBean = gson.fromJson(response.body(), TaobaoListBean.class);
                        if (toBaoBean.getCode() >= 0) {
                            //列表

                            if (toBaoBean.getResult().getGoods_list() != null && toBaoBean.getResult().getGoods_list().size() > 0) {
                                //列表

                                pddListAdapter.addData(toBaoBean.getResult().getGoods_list());
                            }

                        } else {
                            ToastUtils.showShort(toBaoBean.getMsg());
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        loadingDailog.dismiss();
                    }
                });


    }


    private void JDData(String goods_title) {

        Map<String, Object> map = new HashMap<>();
        map.put("user_id", SPUtils.getAppUserId(ShopSearchListActivity.this));
        map.put("query_type", 2);
        map.put("goods_title", goods_title);
        map.put("sortType", sortType);
        map.put("has_coupon", has_coupon);
        map.put("page", page);
        map.put("limit", 10);


        OkGo.<String>post(Constants.JD_INDEX)
                .params("user_id", SPUtils.getAppUserId(ShopSearchListActivity.this))
                .params("query_type", 2)
                .params("goods_title", goods_title)
                .params("sortType", sortType)
                .params("has_coupon", has_coupon)
                .params("page", page)
                .params("limit", 10)
                .params("sign", SignatureUtils.createSignature(map, Constants.SIGN_SECRET))
                .execute(new StringCallback() {


                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        loadingDailog.show();
                    }


                    @Override
                    public void onSuccess(Response<String> response) {
                        setData(response);

                    }

                    private void setData(Response<String> response) {

                        loadingDailog.dismiss();
                        TaobaoListBean toBaoBean = gson.fromJson(response.body(), TaobaoListBean.class);
                        if (toBaoBean.getCode() >= 0) {
                            goods_list.clear();
                            goods_list.addAll(toBaoBean.getResult().getGoods_list());
                            jdListAdapter = new JDListAdapter(R.layout.item_shop_3, null);
                            rvItem.setLayoutManager(new LinearLayoutManager(ShopSearchListActivity.this, LinearLayoutManager.VERTICAL, false));
                            rvItem.setAdapter(jdListAdapter);
                            jdListAdapter.setNewData(goods_list);
                            View notDataView = getLayoutInflater().inflate(R.layout.item_empty_view, (ViewGroup) rvItem.getParent(), false);
                            jdListAdapter.setEmptyView(notDataView);
                            jdListAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                                @Override
                                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                                    Intent intent = new Intent(ShopSearchListActivity.this, ShopItemDetailActivity.class);
                                    Bundle bundle = new Bundle();
                                    ShopCenterMainBean.ResultBean.ShowGoodsListBean.GoodsListBean goodsListBean = goods_list.get(position);
                                    bundle.putString("type", "jd");
                                    bundle.putSerializable("goodsListBean", goodsListBean);
                                    intent.putExtras(bundle);
                                    startActivity(intent);
                                }
                            });
                        } else {
                            ToastUtils.showShort(toBaoBean.getMsg());
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        loadingDailog.dismiss();
                    }
                });


    }

    private void JDLoadMoreData(String goods_title) {

        Map<String, Object> map = new HashMap<>();
        map.put("user_id", SPUtils.getAppUserId(ShopSearchListActivity.this));
        map.put("query_type", 2);
        map.put("goods_title", goods_title);
        map.put("sortType", sortType);
        map.put("has_coupon", has_coupon);
        map.put("page", page);
        map.put("limit", 10);


        OkGo.<String>post(Constants.JD_INDEX)
                .params("user_id", SPUtils.getAppUserId(ShopSearchListActivity.this))
                .params("query_type", 2)
                .params("goods_title", goods_title)
                .params("sortType", sortType)
                .params("has_coupon", has_coupon)
                .params("page", page)
                .params("limit", 10)
                .params("sign", SignatureUtils.createSignature(map, Constants.SIGN_SECRET))
                .execute(new StringCallback() {


                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        loadingDailog.show();
                    }


                    @Override
                    public void onSuccess(Response<String> response) {
                        setData(response);

                    }

                    private void setData(Response<String> response) {

                        loadingDailog.dismiss();
                        TaobaoListBean toBaoBean = gson.fromJson(response.body(), TaobaoListBean.class);
                        if (toBaoBean.getCode() >= 0) {

                            jdListAdapter.addData(toBaoBean.getResult().getGoods_list());
                        } else {
                            ToastUtils.showShort(toBaoBean.getMsg());
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        loadingDailog.dismiss();
                    }
                });


    }


    private void WphData(String key_word) {

        Map<String, Object> map = new HashMap<>();
        map.put("user_id", SPUtils.getAppUserId(ShopSearchListActivity.this));
        map.put("query_type", 2);
        map.put("key_word", key_word);
        map.put("sortType", sortType);
        map.put("page", page);
        map.put("limit", 10);


        OkGo.<String>post(Constants.WPH_INDEX)
                .params("user_id", SPUtils.getAppUserId(ShopSearchListActivity.this))
                .params("query_type", 2)
                .params("key_word", key_word)
                .params("sortType", sortType)
                .params("page", page)
                .params("limit", 10)
                .params("sign", SignatureUtils.createSignature(map, Constants.SIGN_SECRET))
                .execute(new StringCallback() {


                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        loadingDailog.show();
                    }


                    @Override
                    public void onSuccess(Response<String> response) {
                        setData(response);

                    }

                    private void setData(Response<String> response) {
                        loadingDailog.dismiss();
                        WphBean wphBean = gson.fromJson(response.body(), WphBean.class);
                        if (wphBean.getCode() >= 0) {
                            //列表

                            //列表
                            wph_goods_list.clear();
                            wph_goods_list.addAll(wphBean.getResult().getGoods_list());
                            rvItem.setLayoutManager(new LinearLayoutManager(ShopSearchListActivity.this, LinearLayoutManager.VERTICAL, false));
                            wphListAdapter = new WphListAdapter(R.layout.item_shop_wph, null);
                            rvItem.setAdapter(wphListAdapter);
                            wphListAdapter.setNewData(wph_goods_list);
                            View notDataView = getLayoutInflater().inflate(R.layout.item_empty_view, (ViewGroup) rvItem.getParent(), false);
                            wphListAdapter.setEmptyView(notDataView);
                            wphListAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                                @Override
                                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                                    Intent intent = new Intent(ShopSearchListActivity.this, ShopItemDetailActivity.class);
                                    Bundle bundle = new Bundle();
                                    ShopCenterMainBean.ResultBean.ShowGoodsListBean.GoodsListBean goodsListBean = goods_list.get(position);
                                    bundle.putString("type", "wph");
                                    bundle.putSerializable("goodsListBean", goodsListBean);
                                    intent.putExtras(bundle);
                                    startActivity(intent);

                                }
                            });
                        } else {
                            ToastUtils.showShort(wphBean.getMsg());
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        loadingDailog.dismiss();
                    }
                });


    }


    private void WphLoadMoreData(String key_word) {

        Map<String, Object> map = new HashMap<>();
        map.put("user_id", SPUtils.getAppUserId(ShopSearchListActivity.this));
        map.put("query_type", 2);
        map.put("key_word", key_word);
        map.put("sortType", sortType);
        map.put("page", page);
        map.put("limit", 10);


        OkGo.<String>post(Constants.WPH_INDEX)
                .params("user_id", SPUtils.getAppUserId(ShopSearchListActivity.this))
                .params("query_type", 2)
                .params("key_word", key_word)
                .params("sortType", sortType)
                .params("page", page)
                .params("limit", 10)
                .params("sign", SignatureUtils.createSignature(map, Constants.SIGN_SECRET))
                .execute(new StringCallback() {


                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        loadingDailog.show();
                    }


                    @Override
                    public void onSuccess(Response<String> response) {
                        setData(response);

                    }

                    private void setData(Response<String> response) {
                        loadingDailog.dismiss();
                        WphBean wphBean = gson.fromJson(response.body(), WphBean.class);
                        if (wphBean.getCode() >= 0) {
                            //列表

                            if (wphBean.getResult().getGoods_list() != null && wphBean.getResult().getGoods_list().size() > 0) {

                                wphListAdapter.addData(wphBean.getResult().getGoods_list());
                            }

                        } else {
                            ToastUtils.showShort(wphBean.getMsg());
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        loadingDailog.dismiss();
                    }
                });


    }




    private void HPData(String goods_title) {

        Map<String, Object> map = new HashMap<>();
        map.put("user_id", SPUtils.getAppUserId(ShopSearchListActivity.this));
        map.put("goods_title", goods_title);
        map.put("sortType", sortType);
        map.put("page", page);
        map.put("limit", 10);


        OkGo.<String>post(Constants.FIRST_SEARCH)
                .params("user_id", SPUtils.getAppUserId(ShopSearchListActivity.this))
                .params("goods_title", goods_title)
                .params("sortType", sortType)
                .params("page", page)
                .params("limit", 10)
                .params("sign", SignatureUtils.createSignature(map, Constants.SIGN_SECRET))
                .execute(new StringCallback() {


                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        loadingDailog.show();
                    }


                    @Override
                    public void onSuccess(Response<String> response) {
                        setData(response);

                    }

                    private void setData(Response<String> response) {
                        loadingDailog.dismiss();
                        HpSearchBean hpSearchBean = gson.fromJson(response.body(), HpSearchBean.class);
                        if (hpSearchBean.getCode() >= 0) {
                            //列表
                            rvItem.setLayoutManager(new GridLayoutManager(ShopSearchListActivity.this,2, GridLayoutManager.VERTICAL, false));

                            hpSearchListAdapter = new HpSearchListAdapter(R.layout.item_shop_hp, null);
                            hpSearchListAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
                            rvItem.setAdapter(hpSearchListAdapter);
                            hpSearchListAdapter.setNewData(hpSearchBean.getResult().getGoods_list());

                            View notDataView = getLayoutInflater().inflate(R.layout.item_empty_view, (ViewGroup) rvItem.getParent(), false);
                            hpSearchListAdapter .setEmptyView(notDataView);
                            hpSearchListAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                                @Override
                                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

                                    InitGoodDate(hpSearchListAdapter.getData().get(position).getId());
                                }
                            });

                        } else {
                            ToastUtils.showShort(hpSearchBean.getMsg());
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        loadingDailog.dismiss();
                    }
                });


    }



    private void HPLoadMoreData(String goods_title) {

        Map<String, Object> map = new HashMap<>();
        map.put("user_id", SPUtils.getAppUserId(ShopSearchListActivity.this));
        map.put("goods_title", goods_title);
        map.put("sortType", sortType);
        map.put("page", page);
        map.put("limit", 10);


        OkGo.<String>post(Constants.FIRST_SEARCH)
                .params("user_id", SPUtils.getAppUserId(ShopSearchListActivity.this))
                .params("goods_title", goods_title)
                .params("sortType", sortType)
                .params("page", page)
                .params("limit", 10)
                .params("sign", SignatureUtils.createSignature(map, Constants.SIGN_SECRET))
                .execute(new StringCallback() {


                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        loadingDailog.show();
                    }


                    @Override
                    public void onSuccess(Response<String> response) {
                        setData(response);

                    }

                    private void setData(Response<String> response) {
                        loadingDailog.dismiss();
                        HpSearchBean hpSearchBean = gson.fromJson(response.body(), HpSearchBean.class);
                        if (hpSearchBean.getCode() >= 0) {
                            //列表
                            hpSearchListAdapter.addData(hpSearchBean.getResult().getGoods_list());

                        } else {
                            ToastUtils.showShort(hpSearchBean.getMsg());
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        loadingDailog.dismiss();
                    }
                });


    }

    private void InitGoodDate(String goods_id) {
        Map<String, Object> map = new HashMap<>();
        map.put("user_id", SPUtils.getAppUserId(ShopSearchListActivity.this));
        map.put("goods_id", goods_id);


        OkGo.<String>post(Constants.GOODS_LIST_DETAIL)
                .params("user_id", SPUtils.getAppUserId(ShopSearchListActivity.this))
                .params("goods_id", goods_id)
                .params("sign", SignatureUtils.createSignature(map, Constants.SIGN_SECRET))
                .execute(new StringCallback() {


                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        loadingDailog.show();
                    }

                    @Override
                    public void onCacheSuccess(Response<String> response) {
                        super.onCacheSuccess(response);
                        setData(response);
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        setData(response);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        loadingDailog.dismiss();
                    }

                    private void setData(Response<String> response) {
                        loadingDailog.dismiss();
                        GoodDetailsBean goodDetailsBean = gson.fromJson(response.body(), GoodDetailsBean.class);

                        if (goodDetailsBean.getCode() >= 0) {


                            if (goodDetailsBean.getResult().getData_info().getIs_can_pt() == 1) {
                                Intent intent = new Intent(ShopSearchListActivity.this, ProductDetailPtActivity.class);
                                intent.putExtra("goodDetailsBean", goodDetailsBean);
                                intent.putExtra("goods_id", goods_id);
                                startActivity(intent);
                            } else {
                                Intent intent = new Intent(ShopSearchListActivity.this, ProductDetailActivity.class);
                                intent.putExtra("goodDetailsBean", goodDetailsBean);
                                intent.putExtra("goods_id", goods_id);
                                startActivity(intent);
                            }

                        } else {
                            Toast.makeText(ShopSearchListActivity.this, goodDetailsBean.getMsg(), Toast.LENGTH_SHORT).show();
                        }

                    }

                });
    }
}
